package com.syezon.wifikey.home;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;

import com.hodanet.appadvplatclient.ad.AdInfo;
import com.syezon.wifikey.R;
import com.syezon.wifikey.ad.AdPositionEnum;
import com.syezon.wifikey.analysis.AnalysisHelper;
import com.syezon.wifikey.imageloader.ImageLoader;
import com.syezon.wifikey.web.WebHelper;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/9/13.
 */

public class InsertFloatAdDialog extends Dialog {


    @BindView(R.id.iv_insert_float_ad)
    ImageView mIvAd;
    @BindView(R.id.iv_close)
    ImageView mIvClose;
    private AdInfo adInfo;

    public InsertFloatAdDialog(@NonNull Context context) {
        this(context, 0);
    }

    public InsertFloatAdDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        setContentView(View.inflate(context, R.layout.dialog_insert_float_ad, null));
        ButterKnife.bind(this);
    }

    public void setAdInfo(AdInfo adInfo) {
        this.adInfo = adInfo;
    }

    @OnClick({R.id.iv_close, R.id.iv_insert_float_ad})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_insert_float_ad:
                if (adInfo != null) {
                    WebHelper.showAd(getContext(), adInfo.getUrl(), adInfo.getName());
                }
                dismiss();
                break;
            case R.id.iv_close:
                dismiss();
                break;
            default:
                break;
        }
    }

    @Override
    public void show() {
        super.show();
        if (adInfo != null) {
            ImageLoader.getInstance().displayImage(getContext(), adInfo.getPic(), mIvAd);
        } else {
            dismiss();
        }
    }
}
